import matplotlib.pyplot as plt
import numpy as np

from sklearn import linear_model
from sklearn.metrics import mean_squared_error, r2_score
x = np.linspace(0,10,50) # 0到10等间隔产生50个数
b = 1
noise = np.random.uniform(-2, 2, size=50)
y= 5*x + b + noise
lr = linear_model.LinearRegression()
lr.fit(np.reshape(x,(-1,1)),np.reshape(y,(-1,1)))
y_pred =lr.predict(np.reshape(x,(-1,1)))
plt.figure(figsize=(5,5))  # 产生一个窗口
plt.scatter(x,y, color='black')  # 画散点图
plt.plot(x,y_pred,color='blue')
plt.show()